package pl.smath.regex;

import java.util.HashMap;
import java.util.Map;

import pl.smath.expression.model.NumberTerm;
import pl.smath.expression.model.Term;
import pl.smath.expression.model.VariableTerm;
import pl.smath.regex.tree.vertexes.Vertex;

public class Expression {

	/**
	 * Expression is defined by pattern and matching term.
	 * It contains collection of matched values to pattern labels.
	 */
	
	private Map<String, String> env = new HashMap<String, String>();
	
	public Expression(Term term, Vertex pattern) {
		
	}
	
	public Expression(Term term, Vertex pattern, Map<String, String> env) {
		this.env.putAll(env);
	}

	protected Map<String, String> getEnv() {
		return env;
	}
	
	public void addEnv(String key, String val) {
		env.put(key, val);
	}
	
	public NumberTerm getNumber(String label) {
		String ret = env.get("num_" + label.toUpperCase());
		if (ret != null)
			return new NumberTerm(ret);
		else return null;
	}
	
	public VariableTerm getVariable(String label) {
		String ret = env.get("var_" + label.toUpperCase());
		if (ret != null)
			return new VariableTerm(ret);
		else return null;
	}
	
	public NumberTerm getNumber(String label, Integer number) {
		String ret = env.get("num_" + label.toUpperCase() + "_" + number.toString());
		if (ret != null)
			return new NumberTerm(ret);
		else return null;
	}
	
}
